package com.the4man.cnbdw.action;

import com.opensymphony.xwork2.ModelDriven;
import com.the4man.cnbdw.service.LogInfoService;
import com.the4man.cnbdw.utils.Page;
import com.the4man.framework.action.BaseAction;
import com.the4man.framework.model.DataGrid;
import com.the4man.framework.model.LogInfo;
import com.the4man.framework.model.LogInfoExample;
import com.the4man.framework.model.gen.LogInfoExampleBase;
import com.the4man.framework.util.LOG;
import com.the4man.framework.util.PageJson;
import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

@Action(
        value = "logInfoAction",
        results = {@Result(
                name = "addPage",
                location = "/cnbdw/log/add.jsp"
        ), @Result(
                name = "listPage",
                location = "/cnbdw/log/list.jsp"
        ), @Result(
                name = "exportPage",
                location = "/cnbdw/log/export.jsp"
        ), @Result(
                name = "editPage",
                location = "/cnbdw/log/edit.jsp"
        )}
)
public class LogInfoAction extends BaseAction implements ModelDriven<LogInfo> {
    private LogInfo logInfo = new LogInfo();
    @Autowired
    private LogInfoService logInfoService;

    public LogInfoAction() {
    }

    public String indexPage() {
        return "listPage";
    }

    public String toAddPage() {
        return "addPage";
    }

    public String toEditPage() {
        return "editPage";
    }

    public void getAllDatasourceList() {
        try {
            String start = this.getRequest().getParameter("start");
            String end = this.getRequest().getParameter("end");
            LogInfoExample logInfoExample = new LogInfoExample();
            LogInfoExampleBase.Criteria cc = logInfoExample.createCriteria();
            if(StringUtils.isNotEmpty(this.logInfo.getUserName())) {
                cc.andUserNameLike("%" + this.logInfo.getUserName() + "%");
            }

            if(StringUtils.isNotEmpty(this.logInfo.getFunc())) {
                cc.andFuncLike("%" + this.logInfo.getFunc() + "%");
            }

            if(StringUtils.isNotEmpty(start)) {
                cc.andTimeGreaterThanOrEqualTo(start);
            }

            if(StringUtils.isNotEmpty(end)) {
                cc.andTimeLessThanOrEqualTo(end);
            }

            logInfoExample.setOrderByClause("time desc");
            this.logInfoService.countByExample(logInfoExample);
            Page<LogInfo> page = new Page();
            this.setPageProperties(page);
            this.logInfoService.selectByExample(logInfoExample, page);
            DataGrid d = new DataGrid();
            d.setRows(page.getData());
            d.setTotal(Long.valueOf((long)page.getRowCount()));
            this.writeJson(d);
        } catch (Exception var8) {
            LOG.error("获取数据失败", var8, new String[0]);
        }

    }

    public String exportDatasourceList() {
        try {
            String name = new String(this.getRequest().getParameter("name").getBytes("ISO-8859-1"), "GBK");
            String func = new String(this.getRequest().getParameter("func").getBytes("ISO-8859-1"), "GBK");
            String start = this.getRequest().getParameter("start");
            String end = this.getRequest().getParameter("end");
            LogInfoExample logInfoExample = new LogInfoExample();
            LogInfoExampleBase.Criteria cc = logInfoExample.createCriteria();
            if(StringUtils.isNotEmpty(name)) {
                cc.andUserNameLike("%" + name + "%");
            }

            if(StringUtils.isNotEmpty(func)) {
                cc.andFuncLike("%" + func + "%");
            }

            if(StringUtils.isNotEmpty(start)) {
                cc.andTimeGreaterThanOrEqualTo(start);
            }

            if(StringUtils.isNotEmpty(end)) {
                cc.andTimeLessThanOrEqualTo(end);
            }

            logInfoExample.setOrderByClause("time desc");
            this.logInfo.setLogInfoList(this.logInfoService.selectExByExample(logInfoExample));
            BeanUtils.copyProperties(this.logInfo, this.getModel());
        } catch (Exception var7) {
            LOG.error("获取数据失败", var7, new String[0]);
        }

        return "exportPage";
    }

    public String executeModifyResult() {
        try {
            Object instance = this.logInfoService.selectByPrimaryKey(this.logInfo.getId(), LogInfo.class);
            this.getRequest().setAttribute("instance", instance);
        } catch (Exception var2) {
            LOG.error("获取数据失败", var2, new String[0]);
        }

        return "modifyPage";
    }

    public void delete() {
        PageJson json = new PageJson();

        try {
            int i = this.logInfoService.deleteByPrimaryKey(this.getRequest().getParameter("ids"), LogInfo.class);
            if(i > 0) {
                json.setReturnMsg("删除成功！");
                json.setReturnFlag(true);
            } else {
                json.setReturnMsg("删除失败！");
                json.setReturnFlag(false);
            }
        } catch (Exception var3) {
            LOG.error("批量删除失败！", var3, new String[0]);
            json.setReturnMsg("删除失败！");
            json.setReturnFlag(false);
        }

        this.writeJson(json);
    }

    public LogInfo getModel() {
        return this.logInfo;
    }
}
